<template>
  <el-config-provider :locale="locale">
    <router-view />
  </el-config-provider>
</template>

<script lang="ts" setup name="App">
import { computed } from 'vue';
import { useStore } from "@/hooks/store/useStore";
import { LanguageEnum } from '@/enums/LanguageEnum';
import zhCn from "element-plus/es/locale/lang/zh-cn";
import en from "element-plus/es/locale/lang/en";

const { state } = useStore()

const lang = {
  [LanguageEnum.ZH_CN]: zhCn,
  [LanguageEnum.EN_US]: en,
}

const language = computed(() => state.value.app.language)
const locale = computed(() => lang[language.value])

// 解决ResizeObserver loop completed with undelivered notifications.问题
const debounce = (callback: (...args: any[]) => void, delay: number) => {
  let tid: any;
  return function (...args: any[]) {
    const ctx = self;
    tid && clearTimeout(tid);
    tid = setTimeout(() => {
      callback.apply(ctx, args);
    }, delay);
  };
};

const _ = (window as any).ResizeObserver;
(window as any).ResizeObserver = class ResizeObserver extends _ {
  constructor(callback: (...args: any[]) => void) {
    callback = debounce(callback, 20);
    super(callback);
  }
};

</script>

<style lang="scss">
.box {
  padding: 20px;
}
</style>